import { getRandomNumber } from "@/utils/index";
class ColorGenerator {
  constructor() {}
  getAnalogousColors(baseColor: string, num: number = 1) {
    const colors = [];
    for (let i = 0; i < num; i++) {
      const color = this.getAnalogousColor(baseColor);
      colors.push(tinycolor(color).toHexString());
    }
    return colors;
  }

  getAnalogousColor(baseColor: string) {
    const { r, g, b } = tinycolor(baseColor).toRgb();
    const newR = this.getAnalogousRGB(r);
    const newG = this.getAnalogousRGB(g);
    const newB = this.getAnalogousRGB(b);
    return {
      r: newR,
      g: newG,
      b: newB,
    };
  }

  getAnalogousRGB(value: number) {
    if (value > 240) {
      return getRandomNumber(200, 240);
    } else if (value > 200 && value <= 240) {
      return getRandomNumber(value - 10, value + 10);
    } else {
      return getRandomNumber(value - 50, value + 50);
    }
  }
}

export default new ColorGenerator();
